/**
 * The class PeekableStackAsArray implements the interface PeekableStack and extends the class StackAsArray 
 * The class represents a stack using an array of Object data type
 * @author Michael Fildstein, ID: 309161594        
 * @author Tomer Ben Rachel ID: 021982475       
*/  


public class PeekableStackAsArray extends StackAsArray implements PeekableStack {
 
 /**
   * Constructor that receives an integer data type representing the size of the stack and makes a new stack with the given size
   * @param capacity An integer data type representing the size of the stack
  */


	public PeekableStackAsArray(int capacity) {
		super(capacity);
	}
	
   
  /**
   * The method peek looks at the object at index i and returns it without popping it from the stack
   * @param i An integer data type representing the index of the object to be looked at
   * @return An object data type representing the object at index i
  */ 
	public Object peek(int i){
		return super.storage[i];
	}
	
 /**
   * The method size returns the length of the stack
   * @return An integer data type representing the length of the stack
  */   
  
	public int size(){
		return super.top;
	}
	
 /**
   * The method clear cleans the stack of all it's contents
  */   
  
	public void clear(){
		super.top = -1;
	}

 /**
   * The method stackContents returns a string data type containing the contents of the stack
   * @return A string data type containing the values of all the objects inside the stack
  */
	public String stackContents(){
		String ans = "Stack is Empty";
		if (super.top > -1){ 
         ans = "";
			   for (int i = super.top ; i > -1 ; i-- ){
               ans = ans + super.storage[i].toString();
              }
		
		    }		
	  return ans;
	}

}
